package com.lingjtx.common.core;

import com.alibaba.fastjson2.annotation.JSONField;

import java.util.List;

/**
 * 网页数据内容分页model类
 *
 * @author John Liu
 */
public class PageInfo<T> {
    private int pageNo;// 当前页
    private int pageSize;//当前页的数目
    @JSONField(serialize = false)
    private int startNum;// 起始数目
    private int totalPage;// 页数
    private int count;// 总数目
    private List<T> list;

    public PageInfo() {
    }

    public PageInfo(List<T> list) {
        this(0, 0, 0, list);
    }

    public PageInfo(int page, int pageSize) {
        this(page, pageSize, 0, null);
    }

    public PageInfo(int page, int pageSize, int count) {
        this(page, pageSize, count, null);
    }

    public PageInfo(int pageNo, int pageSize, int count, List<T> list) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.count = count;
        this.list = list;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {
        if (count % pageSize == 0) {
            totalPage = count / pageSize;
        } else {
            totalPage = count / pageSize + 1;
        }
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getStartNum() {
        startNum = (pageNo - 1) * pageSize;
        return startNum;
    }

    public void setStartNum(int startNum) {
        this.startNum = startNum;
    }

}
